<?php
    $steady = $this->getName() == "home" && $this->auth != null;
?>
<ul id="pgmenu">
    <li>
        <?php if ($steady) : ?>
            <a class="ajaxLink" href="<?php echo $this->createUrl('home/index')?>?ajax=true">Rumah</a>
        <?php else:?>
            <a href="<?php echo $this->createUrl('home/index')?>">Rumah</a>
        <?php endif;?>
    </li>
    <?php if ($this->auth != null) : ?>
    <li>
            <a href="<?php echo $this->createUrl('profile/view/' . $this->auth->id)?>">Profilku</a>
    </li>
    <li>
        <?php if ($steady) : ?>
            <a class="ajaxLink" href="<?php echo $this->createUrl('photo/index')?>?ajax=true">Foto</a>
        <?php else:?>
            <a href="<?php echo $this->createUrl('photo/index')?>">Foto</a>
        <?php endif;?>
    </li>
    <li>
        <?php if ($steady) : ?>
            <a class="ajaxLink" href="<?php echo $this->createUrl('message/index')?>?ajax=true">Pesan</a>
        <?php else:?>
            <a href="<?php echo $this->createUrl('message/index')?>">Pesan</a>
        <?php endif;?>
    </li>
    <li>
        <a id="chatMenu" href="<?php echo $this->createUrl('chat/index')?>">Obrolan</a>
    </li>
    <?php endif;?>
    <?php if ($this->auth->role->name == "administrator") : ?>
    <li>
            <a href="<?php echo $this->createUrl('users_admin/index')?>">Pengguna</a>
    </li>
    <li>
            <a href="<?php echo $this->createUrl('photos_admin/index')?>">Foto</a>
    </li>
    <?php endif;?>
    <li style="float: right;">
        <form action="<?php echo $this->createUrl('home/index');?>" method="post">
            <input type="text" name="searchTerm"/>
            <input type="submit" value="Search"/>
        </form>
    </li>
</ul>
<script type="text/javascript">
    everyTime(5000 , function() {
        ajaxGet("<?php echo $this->createUrl('chat/countUnreadChat');?>" , function(result){
            if (result != 0)
                document.getElementById('chatMenu').innerHTML = "Obrolan <span style=\"color: #F50505;font-weight: bold;\">("+result+")</span>";
            else
                document.getElementById('chatMenu').innerHTML = "Obrolan";
        });
    });

    var elements = getElementsByClassName("ajaxLink", null , null);

    for (var i in elements) {
        elements[i].onclick = function() {
            var content = document.getElementById("content");
            content.innerHTML = "";
            ajaxGet(this.getAttribute("href"), function(result) {
                content.innerHTML = result;
            });
            return false;
        }
    }
</script>
<br style="clear: both;" />